package com.tuling.code.thread.exam01;

/**
 * 打印奇数的线程
 * @author javaw
 *
 */
public class PrintJishu implements Runnable{
	private Num num;
	
	public PrintJishu(Num num){
		this.num = num;
	}
	
	@Override
	public void run() {
		while (num.i <= 100) {
			synchronized (num) {
				if(num.flag){
					try {
						num.wait();
					} catch (Exception e) {
						e.printStackTrace();
					}
				} else {
					System.out.println(Thread.currentThread().getName() +" -> 奇数 :" +num.i);
					num.i ++;
					num.flag = true;
					num.notify();
				}
			}
		}
	}
	
}
